<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<title>个人资料</title>
<script src="/res/js/common/jquery.1.9.1.min.js" type="text/javascript"></script>
<script src="/res/js/common/common.js" type="text/javascript"></script>
<script src="/res/js/safecenter/frontButton.js" type="text/javascript"></script>
<script src="/res/third/layer/layer.js" type="text/javascript"></script>
<script src="/res/third/laydate/laydate.js" type="text/javascript"></script>
<script src="/res/third/layer/layer.extends.js" type="text/javascript"></script>
<link href="/res/css/respective/safecenter/back-safe.css" rel="stylesheet">
</head>
[#assign menucode="personalData"/]
<body>
	<div class="warp">
    	 [#include "/front/common/front_headAzt.html"]
         <div class="backcontent">
         [#include "/front/common/front_leftAzt.html"]
            <div class="back-main">
            	<div class="inner back-safe">
            	<form id="userform" >
                	 <div class="title">个人资料</div>
                     <div class="safeform">
                          <div class="uploadPic">
                          	  <div class="pic" attrimg="${user.logo!}"><a id="uploadtou" href="javascript:void(0);">上传头像</a></div>
                          	  <input id="id" name="id" type="hidden" value="${user.id!}">
                          	  <input id="logo" name="logo" value="${user.logo!}" type="hidden">
                              <div class="des">
                              	<p>登录名：<b>[#if user.mobile?? && user.mobile?length gt 7]${(user.mobile!)?substring(0,3)}****${(user.mobile!)?substring(7)}[#else]${user.email!}[/#if]</b></p>
                                <p>支持jpg、gif、png等格式的图片</p>
                              </div>
                          </div>
                          <ul>
                          [#if user.company??]
                          	 <li>
                            	<label>公司名：</label>
                                <div class="formfile">
                                	${user.company.companyName!}
                                	<a style="cursor: pointer;" href="javascript:void(0);" onclick="tuichu(${user.id!});">退出公司</a>
                                </div> 
                            </li>
                           [/#if] 
                          	<li>
                            	<label style="width: 60px;"><i class="orange" style="width: auto;height: auto;">*</i>姓名：</label>
                                <div class="formfile">
                                	<input type="text" class="backinput" data-rule="required"  data-msg-required="请输入姓名" name="realName" value="${user.realName!}" maxlength="30"/>
                                </div>
                            </li>
                            <li>
                            	<label>性别：</label>
                                <div class="formfile fileradio">
                                	<label><span class="radioModel [#if user.gender?? && user.gender=='M']radioModelon[/#if]"><input type="radio" name="gender" value="M" [#if user.gender?? && user.gender=='M']checked="checked"[/#if]/></span> 男</label>
                                    <label><span class="radioModel [#if user.gender??][#if user.gender=='F']radioModelon[/#if][/#if]"><input type="radio" name="gender" value="F" [#if user.gender??][#if user.gender=='F']checked="checked"[/#if][#else]checked="checked"[/#if] /></span> 女</label>
                                </div>
                            </li>
                            <!-- 只有管理员会员两个，其他的用户只有一个角色  -->
                            [#if user.roles??]
                            <li>
                            	<label>角色：</label>
                                <div class="formfile">
                                	[#if user.roles[0]??]${user.roles[0].name!}[#else]&nbsp;[/#if]
                                </div>
                            </li>
                            [/#if]
                            <li>
                            	<label>生日：</label>
                                <div class="formfile">
                                <input type="text" class="backinput time laydate-icon" id="birthday" name="birthday" value="[#if user.birthday??]${user.birthday?string("yyyy-MM-dd")}[/#if]"  />
                                </div>
                            </li>
                            [#if (user.mobile?? && user.mobile?length gt 7) && user.email??]
                            <li>
                            	<label>手机：</label>
                                <div class="formfile">
                                	${(user.mobile!)?substring(0,3)}****${(user.mobile!)?substring(7)}<a href="/safecenter/bindOrReset?reset=1&type=1">修改</a>
                                </div>
                            </li>
                           <li>
                            	<label>邮箱：</label>
                                <div class="formfile">
                                	${user.email!}<a href="/safecenter/bindOrReset?reset=1&type=0">修改</a>
                                </div>
                            </li>
                            [#elseif (user.mobile?? && user.mobile?length gt 7)]
                            <li>
                            	<label>手机：</label>
                                <div class="formfile">
                                	${(user.mobile!)?substring(0,3)}****${(user.mobile!)?substring(7)}<a href="/safecenter/bindOrReset?reset=1&type=1">修改</a>
                                </div>
                            </li>
                            <li>
                            	<label>邮箱：</label>
                                <div class="formfile">
                                	验证邮箱，让账户更安全 <a  href="/safecenter/bindOrReset?reset=0&type=0">立即验证</a>
                                </div>
                            </li>
                            [#elseif user.email??]
                            <li>
                            	<label>邮箱：</label>
                                <div class="formfile">
                                	${user.email!}<a href="/safecenter/bindOrReset?reset=1&type=0">修改</a>
                                </div>
                            </li>
                            <li>
                            	<label>手机：</label>
                                <div class="formfile">
                                	验证手机，让账户更安全 <a  href="/safecenter/bindOrReset?reset=0&type=1">立即验证</a>
                                </div>
                            </li>
                            [/#if]
                            <li>
                            	<label>&nbsp;</label>
                                <div class="formfile">
                                	<a href="javascript:void(0);" onclick="ljsave();" class="abtn abtn-large sav">立即保存</a>
                                </div>
                            </li>
                          </ul>
                     </div>
                     </form>
                </div>
            </div>
         </div>
         
  		<!-- 底部菜单-->
		[#include "/front/common/front_footerAzt.html"]
    </div>
    <script src="/res/third/nice-validator/jquery.validator.js?local=zh-CN" type="text/javascript"></script>
    <script type="text/javascript">
    $(function(){
    	var pic=$(".uploadPic").children(".pic");
    	var picurl=pic.attr("attrimg");
    	if(picurl.length>0){
    		pic.css("background-image","url("+picurl+")");
    		pic.css("background-size","95px 95px");
    	}
    });
    var birthday = {
			  elem: '#birthday',
			  format: 'YYYY-MM-DD',
			  festival: true,
			  istoday: false,
			  max: laydate.now(),
			  choose: function(datas){
			  }
			};
    laydate(birthday);
    
    $("#uploadtou").click(function(){
        layer.fileManager(
                {initType:"image","callback":function(data){
                    upcallback(data);
                }}
        );
    });
    function upcallback(response,params){
    	//上传回调
    	  if(response instanceof Array){
              response =response[0];
          }
          layer.closeAll();
          layer.msgShort("上传成功");
          var url = response.url;
          $("#logo").val(url);
          $(".uploadPic").children(".pic").css("background-image","url("+url+")");
          $(".uploadPic").children(".pic").css("background-size","95px 95px");
    }
    
    function ljsave(){
    	//$("input[name='gender']:checked")
    	var form=$("#userform");
    	form.isValid(function(){
        	var me= true;
        	if(me){
               	$.ajax({
        			type : "post",
        			dataType : "json",
        			url : "/safecenter/savePersonalData",
        			data :form.serialize(),
        			success : function(data) {//成功的时候调用
        				if(data.success){
        					 me=false;
        					 layer.msg(data.msg , {time:2000});
        				}else{
        					 me=true;
        					 layer.msg(data.msg , {time:2000});
        				}
        			}
        		});
        	}
    	});
    }
    
    function tuichu(userid){
    	layer.open({
			   title:'提醒'
			  ,content: '是否确认退出公司'
			  ,btn: ['确定', '取消']
			  ,yes: function(index, layero){
			    	$.ajax({
						type : "post",
						dataType : "json",
						url : "/safecenter/unbindCompany",
						data :{},
						success : function(data) {//成功的时候调用
							if(data.success){
								location.reload();
							}else{
								 layer.msg(data.msg , {time:2000});
							}
						}
					});
			  },btn2: function(index, layero){
			  }
			  ,cancel: function(){ 
			    //右上角关闭回调
			  }
			});
    }
    </script>
</body>
</html>
